<?php

namespace app\controller;

use app\BaseController;
use app\service\BigService;
use app\Request;
use think\facade\Config;

class Index extends BaseController
{
    protected $bigServiec;
    protected $r; //Request 对象

    public function __construct(BigService $bigServiec,Request $r)
    {
        $this->bigServiec = $bigServiec;
        $this->r = $r;
        //$this->customMethod($r);
    }

    public function index()
        //https://www.kancloud.cn/a173512/thinkphp6/1327360
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
    }


    //设置
    public function settime(Request $request)
    {
        $og = $request->post();
        $arr['controller']= 'settime';
        $time =  $og['time'];
        Config::set(['settime' => $time], 'time');
        $arr['time']='你设置了轮播秒数'.$time;
        $arr['config'] = Config::get('time');
        return json($arr);
    }

    public function fetchtime(Request $request){
        $og = $request->post();
        $arr['controller']= 'fetchtime';
        $arr['config'] = Config::get('time');
        return json($arr);
    }


    //texttime
    public function iotimeget(Request $request){
        $file = './time.txt';
        $content = file_get_contents($file);
        $arr['time']=$content;
        return json($arr);
    }

    public function codeget(Request $request){
        $timestamp = time();
        $currentHour = date('G', $timestamp);
        $arr['cc']= $currentHour; //17
        $arr['bigcode']= md5($currentHour);

        return json($arr);
    }
    public function iotimeset(Request $request){
        $og = $request->post();
        $time = $og['time'];
        $arr['controller']="iotimeset";
        $file = './time.txt';
        $handle = fopen($file,'c');
        $content = $time;
        file_put_contents($file,$time);
        return json($arr);
    }



    public function bigshow(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $themeid = $og['themeid'];
        $arr = $this->bigServiec->bigshow($uniacid, $id, $themeid);
        $arr['og'] = $og;
        return json($arr);
    }


    /**
     * 1.活动标题
     */
    public function activitietitle(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $arr = $this->bigServiec->activitietitle($uniacid, $id);
        $arr['og'] = $og;
        return json($arr);
    }

    //ordersum
    //订单总量
    public function ordersum(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $arr = $this->bigServiec->ordersum($uniacid, $id);
        $arr['og'] = $og;
        return json($arr);
    }

    //倒计时 countdown
    public function countdown(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $arr = $this->bigServiec->countdown($uniacid, $id);
        $arr['og'] = $og;
        return json($arr);
    }

    //fullgourp
    public function fullgourp(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $arr = $this->bigServiec->fullgourp($uniacid, $id);
        $arr['og'] = $og;
        $arr['action'] = 'fullgourp';
        return json($arr);
    }


    //6 准客，即未支付的 zhuncus
    //record
    //ut
    public function zhuncus(Request $request)
    {
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $arr = $this->bigServiec->zhuncus($uniacid, $themeid);
        return json($arr);
    }

    //7 访客 ui
    public function fanssum(Request $request)
    {
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $arr = $this->bigServiec->fanssum($uniacid, $id);
        return json($arr);
    }

    //ui
    public function ui(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $id = $og['id'];
        $arr = $this->bigServiec->ui($uniacid, $id);
        $arr['og'] = $og;
        return json($arr);
    }

    //ut
    public function ut(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $arr = $this->bigServiec->ut($uniacid, $themeid);
        $arr['og'] = $og;
        $arr['action'] = 'ut';
        return json($arr);
    }

    //8-9 新客数量和老客数量
    //newcus 新客数量
    public function newoldcus(Request $request)
    {
        //入参是小程序post过来的
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $newold = '老';
        $arr = $this->bigServiec->newoldcus($uniacid, $themeid, $newold);
        $arr['og'] = $og;
        $arr['action'] = 'newoldcus';
        return json($arr);
    }

    //10已支付
    //payon 主要是ut
    public function payon(Request $request)
    {
        //同时三个入参
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        //先做已支付
        $arr = $this->bigServiec->payon($uniacid, $themeid);
        $arr['og'] = $og;
        $arr['action'] = 'payon';
        return json($arr);
    }

    //11 未支付
    //payoff 主要是ui
    public function payoff(Request $request)
    {
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        //其实是访客
        $arr = $this->bigServiec->payoff($uniacid, $themeid, $id);
        $arr['og'] = $og;
        $arr['action'] = 'payoff';
        return json($arr);
    }

    //员工排行
    public function cusanking(Request $request)
    {
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        $arr['og'] = $og;
        $arr['action'] = 'cusanking';
        $arr = $this->bigServiec->cusanking($uniacid, $themeid, $id);
        return json($arr);
    }

    //员工表
    public function worker(Request $request)
    {
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        $arr['og'] = $og;
        $arr['action'] = 'worker';
        $arr = $this->bigServiec->worker($uniacid, $themeid, $id);
        return json($arr);
    }

    public function fans(Request $request){
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        $arr = $this->bigServiec->fans($uniacid, $themeid, $id);
        return json($arr);
    }

    public function workertop(Request $request){
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        $arr['og'] = $og;
        $arr['action'] = 'worker';
        $arr = $this->bigServiec->workertop($uniacid, $themeid, $id);
        return json($arr);
    }

    //团队排行
    public function grouptop(Request $request){
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $id = $og['id'];
        $arr['controller'] = 'grouptop';
        $arr = $this->bigServiec->grouptop($uniacid, $themeid, $id);
        return json($arr);
    }

    //红包排行
    public function redtop(Request $request){
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $arr['controller'] = 'redtop';
        $arr = $this->bigServiec->redtop($uniacid, $themeid);
        return json($arr);
    }

    //事件大屏
    public function eventslist(Request $request){
        $og = $request->post();
        $uniacid = $og['uniacid'];
        $themeid = $og['themeid'];
        $arr['controller'] = 'eventslist';
        $arr = $this->bigServiec->eventslist($uniacid, $themeid);
        return json($arr);
    }

    public function testfun(Request $request){
        $og = $request->post();
        $arr['controller']= $og;
        $array = [1, 2, 3, 4, 5,"a"];
        $slicedArray = array_slice($array, 0, 2);
        $arr['one']=$slicedArray;
        // 1  2   3   4
        // 0  1   2   3
        $arr['two']=array_slice($array, 2, count($array)-2);
        //算法2
        $timestamp = time();
        $currentHour = date('G', $timestamp);
        //echo "当前时间是 $currentHour 点";
        $arr['cc']= $currentHour; //17
        $arr['bigcode']= md5($currentHour);
        return json($arr);
    }

    public function codeauth($bigcode){
        $timestamp = time();
        $currentHour = date('G', $timestamp);
        $apicode = md5($currentHour);
        if($bigcode == $apicode){
            return true;
        }
        return false;
    }

}
